<?php
 // NOTE: Uses global variables $dbhost and $database to know where to go.

 // note: mysql_pconnect ought to make sense, but we ran out of connectsion
 // with multiple conns per Apache process
 // global declarations for the case where this is require()d within a function
global $dbname;
global $dbhost;

 $link = mysql_connect($dbhost, "reader", "reader");
 # NOTE that the assumption here is that this is included before anything
 # is printed....may not be valid...
 if (!$link) {
    ?>
<html><head><title>Linux Counter Database Problem</title></head>
<body>
<h1>
<img src="/gifs/Logo-small.png">
The Linux Counter has database problems</h1>
Please try again later. If the problem persists, drop an email to
webmaster&#x40;counter.li.org - they are probably already working on it.
</body>
    <?php
    exit;
 }
 mysql_select_db($dbname);

// Function definitions

function dbcount($table, $where = "all")
{
    if ($where == "all") {
 	$query = mysql_query("select count(*) from $table");
    } else {
        $query = mysql_query("select count(*) from $table where $where");
    }
    if ($query == 0) {
        print("MySQL error: " . mysql_errno() . ":" . mysql_error());
        die("Query in function dbcount($table, $where) failed");
    }
    $arr = mysql_fetch_row($query);
    return $arr[0];
}

?>
